package com.zs.batch.listener;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.stereotype.Component;

/**
 * @author lanyuping
 * @date 2022/11/03 14:36
 */
@Component
@Slf4j
public class SetpListenter implements StepExecutionListener {

    @Override
    public void beforeStep(StepExecution stepExecution) {
        System.out.println("beforeStep");
        log.info("beforeStep : {}", JSONObject.toJSONString(stepExecution));
    }

    @Override
    public ExitStatus afterStep(StepExecution stepExecution) {
        log.info("afterStep : {}", JSONObject.toJSONString(stepExecution));
        System.out.println("afterStep");
        if (stepExecution.getReadSkipCount() > 0 || stepExecution.getProcessSkipCount() > 0 || stepExecution.getWriteSkipCount() > 0) {
            return new ExitStatus(ExitStatus.FAILED.getExitCode());
        } else {
            return ExitStatus.COMPLETED;
        }
    }
}
